﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using _4T.BLL;
using _4T.Data;

namespace _4T
{
    public partial class CMS_ProfileInfoDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["p"] != null)
            {
                string profileCode = Request.QueryString["p"].ToString();
                LoadProfileInfo(profileCode);
                //CMS_ProfileInfo info = new ProfileInfoBLL().GetProfileInfoByProfileInfoCode(profileInfoCode);
                hdfProfileCode.Value = profileCode;
                //LoadProfileStatus(profileCode);
                //hplEdit.NavigateUrl = "ProfileInfoAdd.aspx?p=" + profileCode;
            }
        }

        //private void LoadProfileStatus(string profileCode)
        //{
        //    ProfileBLL profileBLL = new ProfileBLL();
        //    CMS_Profile profile = profileBLL.GetProfileByProfileCode(profileCode);
        //    if (profile != null)
        //    {
        //        switch (profile.Stage)
        //        {
        //            case 2: { lbStage.Text = "Sơ tuyển"; btnFilter.Visible = true; } break;
        //            case 3: { lbStage.Text = "Xác minh"; } break;
        //            case 4: lbStage.Text = "Phê duyệt"; break;
        //            case 5: lbStage.Text = "Thanh toán"; break;
        //        }
        //        switch (profile.Status)
        //        {
        //            case 1: lbStatus.Text = "Đang chờ"; break;
        //            case 2: lbStatus.Text = "Đang thực hiện"; break;
        //            case 3: lbStatus.Text = "Thành công"; break;
        //            case 4: lbStatus.Text = "Thất bại"; break;
        //            default: lbStatus.Text = "Đang chờ";
        //                break;
        //        }
        //        lbLastEditTime.Text = profile.LastEditTime;
        //    }
        //}

        private void LoadProfileInfo(string profileInfoCode)
        {

            //hdfProfileInfoCode.Value = info.ProfileInfoCode;

            // Load patient info
            PatientInfoBLL patientBLL = new PatientInfoBLL();
            PatientInfo patient = patientBLL.GetPatientInfo(profileInfoCode);
            if (patient != null)
            {
                lbPatientName.Text = patient.PatientName;
                lbDOB.Text = patient.Birthday.ToShortDateString();
                lbGender.Text = patient.Gender;
                lbIDNumber.Text = patient.IDNumber;
                lbPermAddr.Text = patient.PermanentAddress;
                lbTempAddr.Text = patient.TemporaryAddress;
                lblMobileNumber.Text = patient.MobileNumber;
                lbPhoneNumber.Text = patient.PhoneNumber;
                lbRepresentativeName.Text = patient.EmergencyRepresentative;
                lbRepresentativePhone.Text = patient.RepresentativePhoneNumber;
                lbLocalContactName.Text = patient.LocalContactPoint;
                lbLocalContactPhone.Text = patient.LocalContactPointPhoneNumber;
                lbMedicalStaff.Text = patient.LocalMedicalStaff;
                lbMedicalStaffPhone.Text = patient.LocalMedicalStaffPhoneNumber;
                lbMedicalFacility.Text = patient.MedicalFacility;
                lbNote.Text = patient.Note;
            }

            // Load medical info
            MedicalInfoBLL medicalBLL = new MedicalInfoBLL();
            MedicalInfo medical = medicalBLL.GetMedicalInfo(profileInfoCode);
            if (medical != null)
            {
                lblDiagnosis.Text = medical.Diagnosis;
                lbMedicalTime.Text = medical.MedicalTime.ToShortDateString();
                lbTreatmentMethod.Text = medical.TreatmentMethod;
                lbSituation.Text = medical.Situation;
                lbSupport.Text = medical.Support;
            }


            // Load info supplier info
            InfoSupplierInfoBLL infoSupplierBLL = new InfoSupplierInfoBLL();
            InfoSupplierInfo supplier = infoSupplierBLL.GetInfoSupplierInfo(profileInfoCode);
            if (supplier != null)
            {
                lbInfoSupplierName.Text = supplier.SupplierName;
                lbInfoSupplierPhone.Text = supplier.PhoneNumber;
                //lbPersonalCode.Text = supplier.PersonalCode;
                lbEmail.Text = supplier.Email;
            }


            // Load Propose Date
            CMS_ProfileInfo info = new ProfileInfoBLL().GetLastProfileInfoByProfileCode(profileInfoCode);
            if (info != null)
            {
                txtProposeDate.Text = info.CreateDate;

                // Load photo, video
                ProfileStageLink stage = new ProfileStageLinkBLL().GetProfileStageLinkByProfileInfoCodeAndStage(info.ProfileInfoCode, 1);
                if (stage != null)
                {
                    if (!string.IsNullOrEmpty(stage.PhotoLink))
                    {
                        if (stage.PhotoLink.IndexOf(';') < 0)
                        {
                            ltrImage.Text = "<img src=\"" + stage.PhotoLink + "\"/>";
                        }
                        else
                        {
                            string[] photoLinks = stage.PhotoLink.Split(';');
                            for (int i = 0; i < photoLinks.Length; i++)
                            {
                                ltrImage.Text += "<img src=\"" + photoLinks[i] + "\"/><br/>";
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(stage.VideoLink))
                    {
                        if (stage.PhotoLink.IndexOf(';') < 0)
                        {
                            Page.ClientScript.RegisterStartupScript(GetType(), "playvideo", "playvideo('" + stage.VideoLink + "');", true);
                        }
                        else
                        {
                            string[] videoLinks = stage.VideoLink.Split(';');
                            Page.ClientScript.RegisterStartupScript(GetType(), "playvideo", "playvideo('" + videoLinks[0] + "');", true);
                        }
                    }

                    txtDescription.Text = stage.Description;
                }
            }
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            //Response.Redirect("CMS_AddProfile.aspx?p=" + hdfProfileCode.Value);
        }
    }
}